package com.cheys.webapp.controller;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.cheys.webapp.model.BBS;
import com.cheys.webapp.model.Case;
import com.cheys.webapp.model.Page;
import com.cheys.webapp.model.User;
import com.cheys.webapp.model.WebSite;
import com.cheys.webapp.service.AdminService;
import com.cheys.webapp.service.CaseService;
import com.cheys.webapp.util.DateUtil;
import com.cheys.webapp.util.LogUtil;
import com.cheys.webapp.util.StringUtil;
import com.cheys.webapp.util.TypeHelper;

@Controller
@RequestMapping("/axxf")
public class CaseController {
	@Autowired
	private CaseService caseService;
	@Autowired
	private AdminService adminService;
	
	private Logger logger = LogUtil.getLogger();
	
	@RequestMapping("/getAllCase")
	public String getAllCase(Case c,Page page,HttpServletRequest request){
		LogUtil.getLogger(this.getClass()).info("开始处理>>查询所有资源信息逻辑<<");
		try {
			List<Case> select = this.caseService.select(c,page);
			List<Case> things1 = new ArrayList<Case>();
			List<Case> things2 = new ArrayList<Case>();
			List<Case> things3 = new ArrayList<Case>();
			for (Case case1 : select) {
				if(case1.getBelong() == 1){
					things1.add(case1);
				}
				if(case1.getBelong() == 2){
					things2.add(case1);
				}
				if(case1.getBelong() == 3){
					things3.add(case1);
				}
			}
			request.setAttribute("things1", things1);
			request.setAttribute("things2", things2);
			request.setAttribute("things3", things3);
			if(null == request.getSession().getAttribute("webinfo")){
				WebSite webinfo = this.adminService.getWebsitInfo();
				request.getSession().setAttribute("webinfo",webinfo );
			}
		} catch (Exception e) {
			LogUtil.getLogger(this.getClass()).debug("查询资源信息逻辑异常："+e);
		}
		return "allCase.jsp";
	}
	@RequestMapping("/getOneCase")
	public String getOneCase(int id,HttpServletRequest request,HttpServletResponse response){
		LogUtil.getLogger(this.getClass()).info("开始处理>>查询资源信息逻辑<<");
		try {
			Case case1 = this.caseService.selectOne(id);
			if(case1.getBelong()>=6 && case1.getBelong() <=9){
				logger.info("修复实例需要查询评论信息");
				List<BBS> bbsInfoByCaseId = this.caseService.getBBSInfoByCaseId(case1.getId());
				request.setAttribute("bbs", bbsInfoByCaseId);
			}
			request.setAttribute("c", case1);
			if(null == request.getSession().getAttribute("webinfo")){
				WebSite webinfo = this.adminService.getWebsitInfo();
				request.getSession().setAttribute("webinfo",webinfo );
			}
		} catch (Exception e) {
			LogUtil.getLogger(this.getClass()).debug("查询资源信息逻辑异常："+e);
		}
		return "/oneCase.jsp";
	}
	@RequestMapping("/getAllNews")
	public String getAllNews(HttpServletRequest request){
		try {
			List<Case> news = this.caseService.getCase(new Case(7));
			request.setAttribute("news", news);
			if(null == request.getSession().getAttribute("webinfo")){
				WebSite webinfo = this.adminService.getWebsitInfo();
				request.getSession().setAttribute("webinfo",webinfo );
			}
		} catch (Exception e) {
			return "/error.html";
		}
		return "/allCase.jsp";
	}
	@RequestMapping("/aboutus")
	public String getAboutusInfo(HttpServletRequest request){
		logger.info("获取关于我们-公司简介信息");
		try {
			List<Case> case1 = this.caseService.getCase(new Case(3));
			List<Case> members = this.caseService.getCase(new Case(4));
			if(members.size() > 0){
				TypeHelper typeHelper = new TypeHelper();
				Map<String, String> rank = typeHelper.getMemberRankMap();
				Map<String, String> state = typeHelper.getMemberStateMap();
				for (Case c : members) {
					c.setIsneturlDesc(rank.get(String.valueOf(c.getIsneturl())));
					c.setFmResourceDesc(state.get(String.valueOf(c.getFmResource())));
				}
				request.setAttribute("members", members);
			}
			if(case1.size() > 0 ){
				request.setAttribute("aboutus", case1.get(0));
			}
			if(null == request.getSession().getAttribute("webinfo")){
				WebSite webinfo = this.adminService.getWebsitInfo();
				request.getSession().setAttribute("webinfo",webinfo );
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "/aboutus.jsp";
	}
	@RequestMapping("/allService")
	public String getAllService(HttpServletRequest request){
		try {
			List<Case> services = this.caseService.getCase(new Case(2));
			request.setAttribute("news", services);
			if(null == request.getSession().getAttribute("webinfo")){
				WebSite webinfo = this.adminService.getWebsitInfo();
				request.getSession().setAttribute("webinfo",webinfo );
			}
		} catch (Exception e) {
			return "/error.html";
		}
		return "/allCase.jsp";
	}
	@RequestMapping("/allPrice")
	public String getAllPrice(HttpServletRequest request){
		try {
			List<Case> prices = this.caseService.getCase(new Case(8));
			request.setAttribute("news", prices);
			if(null == request.getSession().getAttribute("webinfo")){
				WebSite webinfo = this.adminService.getWebsitInfo();
				request.getSession().setAttribute("webinfo",webinfo );
			}
		} catch (Exception e) {
			return "/error.html";
		}
		return "/allCase.jsp";
	}
	@RequestMapping("/getAllExamples")
	public String getAllExamples(HttpServletRequest request){
		try {
			List<Case> services = this.caseService.getCase(new Case(9));
			request.setAttribute("examples", services);
			if(null == request.getSession().getAttribute("webinfo")){
				WebSite webinfo = this.adminService.getWebsitInfo();
				request.getSession().setAttribute("webinfo",webinfo );
			}
		} catch (Exception e) {
			return "/error.html";
		}
		return "/allExample.jsp";
	}
	@RequestMapping("/index")
	public void toIndex(HttpServletRequest request,HttpServletResponse response) throws Exception{
		logger.info("读取网站信息……");
//		this.caseService.initList();
		String param = request.getParameter("param");
		WebSite webinfo = this.adminService.getWebsitInfo();
		request.getSession().setAttribute("webinfo",webinfo );
		List<Case> advs = this.caseService.getCase(new Case(1));
		request.setAttribute("advs",advs);
		List<Case> services = this.caseService.getCase(new Case(2));
		if(services.size()>3)
			services = services.subList(0, 3);
		request.setAttribute("services",services);
		List<Case> list = this.caseService.getCase(new Case(6));
//		if(list.size() > 3){
//			list = list.subList(0, 3);
//		}
		List<Case> news = this.caseService.getCase(new Case(7));
		if(news.size() > 2){
			news = news.subList(0, 2);
		}
		List<Case> prices = this.caseService.getCase(new Case(8));
		if(prices.size() > 4){
			request.setAttribute("priceSize", prices.size());
			prices = prices.subList(0, 4);
		}
		List<Case> examples = this.caseService.getCase(new Case(9));
		if(examples.size() > 2){
			examples = examples.subList(0, 2);
		}
		Map<String,List<Case>> maplist = new HashMap<String, List<Case>>();
		if(list.size() > 0){
			Set<String> provSet = new HashSet<String>();
			for (Case c : list) {
				if(c.getFmResource().indexOf("/") > -1){
					c.setFmResourceDesc(c.getFmResource().substring(0,c.getFmResource().lastIndexOf("/")));
					String[] isnetds = c.getFmResource().substring(0, c.getFmResource().lastIndexOf("/")).split("/");;
					c.setIsneturlDesc(isnetds[0]);
				}
				provSet.add(c.getIsneturlDesc());
			}
			for (String str : provSet) {
				List<Case> sublist = new ArrayList<Case>();
				for (Case c : list) {
					if(c.getIsneturlDesc().equals(str)){
						sublist.add(c);
					}
				}
				maplist.put(str, sublist);
			}
		}
		request.setAttribute("sps", maplist);
		List<Case> case1 = this.caseService.getCase(new Case(3));
		if(case1.size() > 0){
			request.setAttribute("aboutus", case1.get(0));
		}
		if(news.size() > 0){
			for (Case n : news) {
				n.setCreatetime(DateUtil.formatDate(n.getCreatetime(), DateUtil.DATE_FORMAT_CN_YYYYMMDD));
			}
		}
		if(prices.size() > 0){
			for (Case p : prices) {
				p.setIsneturlDesc(new TypeHelper().getPriceMap().get(p.getIsneturl()));
			}
		}
		if(examples.size() > 0){
			for (Case n : examples) {
				n.setCreatetime(DateUtil.formatDate(n.getCreatetime(), DateUtil.DATE_FORMAT_CN_YYYYMMDD));
			}
		}
		request.setAttribute("news", news);
		request.setAttribute("prices", prices);
		request.setAttribute("examples", examples);
		String path = System.getProperty("webapp.root");
		if(!path.endsWith(File.separator)){
			path = path.concat(File.separator);
		}
		path = path.concat("_index.html");
		createIndexHtml(request,webinfo,path, advs, services, maplist, case1.get(0), news, prices, examples, param);
//		if(StringUtil.isNotBlank(param)){
//			return "/index.jsp?param="+param;
//		}
//		return "/index.jsp";
	}
	private void createIndexHtml(HttpServletRequest request, WebSite webinfo,String path,List<Case> advs,List<Case> services,
			Map<String,List<Case>> sps,Case aboutus,List<Case> news,List<Case> prices,List<Case> examples,String param) {
		// TODO Auto-generated method stub
		logger.info("创建文件："+path);
		try {
			File file = new File(path);
			StringBuffer sb_index = new StringBuffer();
			sb_index.append("<!DOCTYPE html>\n");
			sb_index.append("<html lang=\"zh-cn\">\n");
			sb_index.append("<head>\n");
			sb_index.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n");
			sb_index.append("<meta http-equiv=\"X-UA-COMPATIBLE\" IE=\"edge\">\n");
			sb_index.append("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n");
			sb_index.append("<title>"+webinfo.getTitle()+"</title>");
			sb_index.append("<meta name=\"description\" content=\""+webinfo.getDescript()+"\" />\n");
			sb_index.append("<meta name=\"author\" content=\""+webinfo.getOwner()+"\" />\n");
			sb_index.append("<meta name=\"keyworkds\" content=\""+webinfo.getKeyword()+"\" />\n");
			sb_index.append("<!-- css -->\n");
			sb_index.append("<link href=\"css/bootstrap.min.css\" rel=\"stylesheet\" />\n");
			sb_index.append("<link rel=\"stylesheet\" href=\"css/pintuer.css\">\n");
			sb_index.append("<link rel=\"stylesheet\" href=\"css/admin.css\">\n");
			sb_index.append("<link href=\"css/fancybox/jquery.fancybox.css\" rel=\"stylesheet\">\n");
			sb_index.append("<link href=\"css/flexslider.css\" rel=\"stylesheet\" />\n");
			sb_index.append("<link href=\"css/style.css\" rel=\"stylesheet\" />\n");
			sb_index.append("<script src=\"js/jquery.js\"></script>\n");
			sb_index.append("<script>(function(){var bp = document.createElement('script');\n");
			sb_index.append("var curProtocol = window.location.protocol.split(':')[0];\n");
			sb_index.append("if (curProtocol === 'https'){\n");
			sb_index.append("bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';\n");
			sb_index.append("}\n");
			sb_index.append("else{\n");
			sb_index.append("bp.src = 'http://push.zhanzhang.baidu.com/push.js';\n");
			sb_index.append("}\n");
			sb_index.append(" var s = document.getElementsByTagName(\"script\")[0];\n");
			sb_index.append("s.parentNode.insertBefore(bp, s);\n");
			sb_index.append("})();\n");
			sb_index.append("</script>\n");
			sb_index.append("<script src=\"js/jquery.easing.1.3.js\"></script>\n");
			sb_index.append("<script src=\"js/bootstrap.min.js\"></script>\n");
			sb_index.append("<script src=\"js/jquery.fancybox.pack.js\"></script>\n");
			sb_index.append("<script src=\"js/jquery.fancybox-media.js\"></script>\n");
			sb_index.append("<script src=\"js/portfolio/jquery.quicksand.js\"></script>\n");
			sb_index.append("<script src=\"js/portfolio/setting.js\"></script>\n");
			sb_index.append("<script src=\"js/jquery.flexslider.js\"></script>\n");
			sb_index.append("<script src=\"js/animate.js\"></script>\n");
			sb_index.append("<script src=\"js/custom.js\"></script>\n");
			sb_index.append("<script type=\"text/javascript\" src=\"js/jquery.imagezoom.min.js\"></script>\n");
			sb_index.append("<script type=\"text/javascript\">\n");
			sb_index.append("	$(function(){\n");
			sb_index.append("	  $(\".jqzoom\").imagezoom();\n");
			sb_index.append("	  $(\".leftnav h2\").click(function(){\n");
			sb_index.append("		  $(this).next().slideToggle(200);\n");
			sb_index.append("		  $(this).toggleClass(\"on\");\n");
			sb_index.append("	  });\n");
			sb_index.append("	  $(\".leftnav ul li a\").click(function(){\n");
			sb_index.append("		    $(\"#a_leader_txt\").text($(this).text());\n");
			sb_index.append("	  		$(\".leftnav ul li a\").removeClass(\"on\");\n");
			sb_index.append("			$(this).addClass(\"on\");\n");
			sb_index.append("	  });\n");
			sb_index.append("	  $(\"#nav_top li a\").click(function(){\n");
			sb_index.append("		  $(this).parent(\"ul\").find(\"li\").removeClass(\"active\");\n");
			sb_index.append("		  $(this).parent().addClass(\"active\");\n");
			sb_index.append("	  });\n");
			sb_index.append("	});\n");
			sb_index.append("	function switchById(id){\n");
			sb_index.append("document.getElementById(id).scrollIntoView();\n");
			sb_index.append("	}\n");
			sb_index.append("</script>\n");
			sb_index.append("<script>\n");
			sb_index.append("(function(){\n");
			sb_index.append("    var bp = document.createElement('script');\n");
			sb_index.append("    var curProtocol = window.location.protocol.split(':')[0];\n");
			sb_index.append("    if (curProtocol === 'https'){\n");
			sb_index.append("   bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';\n");
			sb_index.append("  }\n");
			sb_index.append("  else{\n");
			sb_index.append("  bp.src = 'http://push.zhanzhang.baidu.com/push.js';\n");
			sb_index.append("  }\n");
			sb_index.append("    var s = document.getElementsByTagName(\"script\")[0];\n");
			sb_index.append("    s.parentNode.insertBefore(bp, s);\n");
			sb_index.append("})();\n");
			sb_index.append("</script>\n");
			sb_index.append("<style type=\"text/css\">\n");
			sb_index.append("    div.zoomDiv{z-index:999;position:absolute;top:0px;left:0px;width:300px !important;height:300px !important;background:#ffffff;border:1px solid #ddd;display:none;text-align:center;overflow:hidden;}\n");
			sb_index.append("    div.zoomMask{position:absolute;background:url(\"/img/mask.png\") repeat scroll 0 0 transparent;cursor:move;z-index:1;}\n");
			sb_index.append("</style>\n");
			sb_index.append("</head>\n");
			sb_index.append("<body>\n");
			//body内容
			sb_index.append("	<div id=\"wrapper\">\n");
			sb_index.append("		<a id=\"maodian1\" name=\"maodian1\"></a>\n");
			sb_index.append("		<!-- start header -->");
			sb_index.append("		<header>\n");
			sb_index.append("			<div class=\"navbar navbar-default navbar-static-top\">\n");
			sb_index.append("				<div class=\"container\">\n");
			sb_index.append("					<div class=\"navbar-header\">\n");
			sb_index.append("						<button type=\"button\" class=\"navbar-toggle\" data-toggle=\"collapse\" data-target=\".navbar-collapse\">\n");
			sb_index.append("							<span class=\"icon-bar\"></span> <span class=\"icon-bar\"></span> <span	class=\"icon-bar\"></span>\n");
			sb_index.append("						</button>\n");
			sb_index.append("						<a class=\"navbar-brand\" href=\"\"><img src=\""+webinfo.getLogo()+"\" alt=\""+webinfo.getTitle()+"\" width=\"158\" height=\"42\"/></a>\n");
			sb_index.append("					</div>\n");
			sb_index.append("					<div class=\"navbar-collapse collapse \">\n");
			sb_index.append("						<ul class=\"nav navbar-nav\" id=\"nav_top\">\n");
			sb_index.append("							<li class=\"active\"><a href=\"javascript:void(0);\" onclick=\"switchById('wrapper')\">首页</a></li>\n");
			sb_index.append("							<li><a href=\"javascript:void(0)\" onclick=\"switchById('services')\">提供服务</a></li>\n");
			sb_index.append("							<li><a href=\"javascript:void(0)\" onclick=\"switchById('price')\">产品展示</a></li>\n");
			sb_index.append("							<li><a href=\"javascript:void(0)\" onclick=\"switchById('content')\">服务网点</a></li>\n");
			sb_index.append("							<li><a href=\"javascript:void(0)\" onclick=\"switchById('content')\">最近新闻</a></li>\n");
			sb_index.append("							<li><a href=\"contact.jsp\">联系我们</a></li>\n");
			sb_index.append("						</ul>\n");
			sb_index.append("					</div>\n");
			sb_index.append("				</div>\n");
			sb_index.append("			</div>\n");
			sb_index.append("		</header>\n");
			sb_index.append("		<!-- end header -->\n");
			sb_index.append("		<section id=\"featured\">\n");
			sb_index.append("			<!-- Slider -->\n");
			sb_index.append("			<div id=\"main-slider\" class=\"flexslider\">\n");
			sb_index.append("				<ul class=\"slides\" id = \"advs\">\n");
			for(Case c : advs){
				sb_index.append("						<li><img src=\""+c.getResource()+"\" alt=\""+c.getTitle()+"\" /></li>\n");
			}
			sb_index.append("				</ul>\n");
			sb_index.append("			</div>\n");
			sb_index.append("			<!-- end slider -->\n");
			sb_index.append("		</section>\n");
			sb_index.append("		<a name=\"maodian_service\" id=\"maodian_service\"></a>\n");
			sb_index.append("		<section id=\"services\" style=\"width: 80%;position: relative;margin-left: 10%;margin-right: 10%;\">\n");
			sb_index.append("			<div class=\"container\">\n");
			sb_index.append("				<div class=\"row service-v1 margin-bottom-40\">\n");
			for(int i=0;i<services.size();i++){
				Case c = services.get(i);
				if(i < 2){
					sb_index.append("<div class=\"col-md-5\">\n");
					sb_index.append("<span style=\"width:100%;position: relative;text-align: center;\">\n");
					sb_index.append("<h2>"+c.getTitle()+"</h2>\n");
					sb_index.append("</span>\n");
					if(c.getType() == 1){
						sb_index.append("<a href=\"axxf/getExampleByServiceId.do?serviceId="+c.getId()+"\"><img class=\"img-responsive\" src=\""+c.getResource()+"\" alt=\""+c.getTitle()+"\"/></a>\n");
					}else if(c.getType() == 2){
						sb_index.append("<video  id=\"showVedio\" poster=\""+c.getFmResource()+"\" src=\""+c.getResource()+"\" controls=\"controls\" preload=\"none\" width=\"100%\" height=\"100%\" style=\"max-height: 210px\"></video>\n");
					}else if(c.getType() == 3){
						sb_index.append("<embed type=\"application/x-shockwave-flash\" src=\""+c.getResource()+"\" width=\"357\" height=\"210\" id=\"showSwf\" quality=\"high\" wmode=\"transparent\" scale=\"noscale\" menu=\"false\" allowfullscreen=\"true\" flashvars=\"lm=\">\n");
					}
					sb_index.append("<span style=\"width:100%;position: relative;\">\n");
					sb_index.append("<p>"+c.getContent()+"</p>\n");
					sb_index.append("</span>\n");
					sb_index.append("</div><div class=\"col-xs-1\"></div>\n");
				}
			}
			sb_index.append("</div>\n");
			if(services.size() > 2){
				sb_index.append("<div style=\"width: 80%;position:relative;text-align: center;margin-left: 5%;margin-right: 10%;\" ><a style=\"width:100%;position:relative; \" href=\"axxf/allService.do\">更多服务︾</a></div>\n");
			}
			sb_index.append("</div>\n");
			sb_index.append("</section>\n");
			sb_index.append("<a id=\"maodian_aboutus\" name=\"maodian_aboutus\"></a>\n");
			sb_index.append("<section class=\"callaction\" id=\"aboutus\">\n");
			sb_index.append("<div class=\"container\">\n");
			sb_index.append("<div class=\"row\">\n");
			sb_index.append("<div class=\"col-md-4\">\n");
			sb_index.append("<a href=\"axxf/aboutus.do\"><img src=\""+aboutus.getResource()+"\" alt=\""+aboutus.getTitle()+"\" width=\"100%\" /></a>\n");
			sb_index.append("</div>\n");
			sb_index.append("<div class=\"col-md-8\">\n");
			sb_index.append("<div><h1>\n");
			sb_index.append("<span><span class=\"blue_text\">"+aboutus.getTitle()+"</span></span>\n");
			sb_index.append("</h1><span class=\"clear spacer_responsive_hide_mobile \" style=\"height: 13px; display: block;\"></span>\n");
			sb_index.append("<p>"+aboutus.getContent()+"</p>\n");
			sb_index.append("</div></div></div></div>\n");
			sb_index.append("</section>\n");
			sb_index.append("<a id=\"maodian_price\" name=\"maodian_price\"></a>\n");
			sb_index.append("<section id=\"price\">\n");
			sb_index.append("<div class=\"container\">\n");
			sb_index.append("<div class=\"row\">\n");
			sb_index.append("<div class=\"col-lg-12\"><h4>产品展示</h4></div>\n");
			for(Case c : prices){
				sb_index.append("<div class=\"col-lg-3\">\n");
				sb_index.append("<div class=\"pricing-box-item\">\n");
				sb_index.append("		<div class=\"pricing-heading\">\n");
				sb_index.append("			<h3><strong><a href=\"axxf/getOneCase.do?id="+c.getId()+"\" style=\"color: white;\">"+c.getTitle()+"</a></strong></h3>\n");
				sb_index.append("		</div>\n");
				sb_index.append("		<div class=\"pricing-terms\">\n");
				if(StringUtil.isNotBlank(c.getResource())){
					sb_index.append("			<img src=\""+c.getResource()+"\" data-original=\""+c.getResource()+"\" rel=\""+c.getResource()+"\" alt=\""+c.getTitle()+"\" class=\"jqzoom\" style=\"display: inline; cursor: crosshair; width: 100%;position: relative;\"/>\n");
				}
				sb_index.append("			<h6><a href=\"axxf/getOneCase.do?id="+c.getId()+"\">详情介绍</a></h6>\n");
				sb_index.append("		</div>\n");
				sb_index.append("</div>\n");
				sb_index.append("</div>\n");
			}
			sb_index.append("</div>\n");
//			if(prices.size() > 4){
//				sb_index.append("<div style=\"width: 80%;position:relative;text-align: center;margin-left: 5%;margin-right: 10%;\" ><a style=\"width:100%;position:relative; \" href=\"axxf/allPrice.do\">更多产品︾</a></div>\n");
//			}
			sb_index.append("</div></section>\n");
			sb_index.append("<a id=\"maodian_content\" name=\"maodian_content\"></a>\n");
			sb_index.append("<section id=\"content\">\n");
			sb_index.append("<div class=\"container\">\n");
			sb_index.append("<div class=\"row\">\n");
			sb_index.append("<div class=\"col-md-4\">\n");
			sb_index.append("<!-- Heading and para -->\n");
			sb_index.append("<div class=\"block-heading-one\">\n");
			sb_index.append("<h3><span>服务网点</span></h3>\n");
			sb_index.append("</div>\n");
			sb_index.append("<div class=\"leftnav\" style=\"position: relative; width: 80%;height: 100%;bottom: 20px;top: 10px;\">\n");
			int sps_count = 1;
			for(Map.Entry<String, List<Case>> entry : sps.entrySet()){
				sb_index.append("<h2><span class=\"icon-star\"></span>"+entry.getKey()+"</h2>\n");
				if(sps_count == 1){
					sb_index.append("<ul style=\"display:block\">\n");
				}else{
					sb_index.append("<ul>\n");
				}
				for (Case case1 : entry.getValue()) {
					sb_index.append("<li><a href=\"axxf/getOneCase.do?id="+case1.getId()+"\"><span class=\"icon-caret-right\"></span>"+case1.getFmResource()+"</a></li>\n");
				}
				sb_index.append("</ul>\n");
			}
			sb_index.append("</div></div>\n");
			sb_index.append("<div class=\"col-xs-8 col-sm-8 col-md-4\">\n");
			sb_index.append("<div class=\"latest-post-wrap pull-left\" >\n");
			sb_index.append("<h3><span>修复实例</span></h3>\n");
			for(Case c : examples){
				sb_index.append("<div class=\"post-item-wrap pull-left col-sm-6 col-md-12 col-xs-12\">\n");
				if(c.getType() == 2){
					sb_index.append("<img src=\""+c.getFmResource()+"\" class=\"img-responsive post-author-img\" alt=\""+c.getTitle()+"\">\n");
				}else{
					sb_index.append("<img src=\""+c.getResource()+"\" class=\"img-responsive post-author-img\" alt=\""+c.getTitle()+"\">\n");
				}
				sb_index.append("<div class=\"post-content1 pull-left col-md-9 col-sm-9 col-xs-8\">\n");
				sb_index.append("<div class=\"post-title pull-left\">\n");
				sb_index.append("<a href=\"axxf/getOneCase.do?id="+c.getId()+"\" target=\"_blank\">"+c.getTitle()+"</a>\n");
				sb_index.append("</div><div class=\"post-meta-top pull-left\">\n");
				sb_index.append("<ul><li><i class=\"fa fa-calendar\"></i>"+c.getCreatetime()+"</li></ul>\n");
				sb_index.append("</div></div>\n");
				sb_index.append("<div class=\"post-content2 pull-left\">\n");
				sb_index.append("<p><a href=\"axxf/getOneCase.do?id="+c.getId()+"\" target=\"_blank\">点击了解详情</a></p>\n");
				sb_index.append("</div></div>\n");
			}
			sb_index.append("<span class=\"post-meta-bottom\"><a href=\"axxf/getAllExamples.do\">更多实例</a></span>\n");
			sb_index.append("</div></div>\n");
			sb_index.append("<div class=\"col-xs-8 col-sm-8 col-md-4\">\n");
			sb_index.append("<div class=\"latest-post-wrap pull-left\" >\n");
			sb_index.append("<h3><span>热点新闻</span></h3>\n");
			for(Case c :news){
				sb_index.append("<div class=\"post-item-wrap pull-left col-sm-6 col-md-12 col-xs-12\">\n");
				sb_index.append("<img src=\""+c.getResource()+"\" class=\"img-responsive post-author-img\" alt=\""+c.getTitle()+"\">\n");
				sb_index.append("<div class=\"post-content1 pull-left col-md-9 col-sm-9 col-xs-8\">\n");
				sb_index.append("<div class=\"post-title pull-left\">\n");
				sb_index.append("<a href=\"axxf/getOneCase.do?id="+c.getId()+"\">"+c.getTitle()+"</a>\n");
				sb_index.append("</div>\n");
				sb_index.append("<div class=\"post-meta-top pull-left\">\n");
				sb_index.append("<ul><li><i class=\"fa fa-calendar\"></i>"+c.getCreatetime()+"</li></ul>\n");
				sb_index.append("</div></div>\n");
				sb_index.append("<div class=\"post-content2 pull-left\">\n");
				sb_index.append("<p>\n");
				sb_index.append("</p></div></div>\n");
			}
			sb_index.append("<span class=\"post-meta-bottom\"><a href=\"axxf/getAllNews.do\">更多新闻</a></span>\n");
			sb_index.append("</div></div></div>\n");
			sb_index.append("<div class=\"row\"></div>\n");
			sb_index.append("</div>\n");
			sb_index.append("</section>\n");
			sb_index.append("<footer>\n");
			sb_index.append("<div class=\"container\">\n");
			sb_index.append("<div class=\"row\">\n");
			sb_index.append("<div class=\"col-lg-3\">\n");
			sb_index.append("<div class=\"widget\">\n");
			sb_index.append("<h5 class=\"widgetheading\">Our Contact</h5>\n");
			sb_index.append("<address>\n");
			sb_index.append("<strong>"+webinfo.getTitle()+"</strong><br>\n");
			sb_index.append(webinfo.getAddress()+"<br>\n");
			sb_index.append("</address>\n");
			sb_index.append("<p>\n");
			sb_index.append("<i class=\"icon-phone\"></i> "+webinfo.getPhone()+" &nbsp; "+webinfo.getTelphone()+" <br>\n");
			sb_index.append("<i class=\"icon-envelope-alt\"></i> "+webinfo.getEmail()+"\n");
			sb_index.append("</p></div></div>\n");
			sb_index.append("<div class=\"col-lg-3\">\n");
			sb_index.append("<div class=\"widget\">\n");
			sb_index.append("<h5 class=\"widgetheading\">快速链接</h5>\n");
			sb_index.append("<ul class=\"link-list\">\n");
			sb_index.append("<li><a href=\"javascript:void(0);\" onclick=\"switchById('wrapper')\">顶部</a></li>\n");
			sb_index.append("<li><a href=\"axxf/aboutus.do\">关于我们</a></li>\n");
			sb_index.append("<li><a href=\"javascript:void(0)\" onclick=\"switchById('services')\">服务</a></li>\n");
			sb_index.append("<li><a href=\"javascript:void(0)\" onclick=\"switchById('content')\">服务网点</a></li>\n");
			sb_index.append("<li><a href=\"contact.jsp\">联系我们</a></li>\n");
			sb_index.append("</ul></div></div>\n");
			sb_index.append("<div class=\"col-lg-3\">\n");
			sb_index.append("<div class=\"widget\">\n");
			sb_index.append("<h5 class=\"widgetheading\">最近新闻</h5>\n");
			sb_index.append("<ul class=\"link-list\">\n");
			List<Case> new_1 = news;
			if(news.size() > 6){
				new_1 = news.subList(0, 6);
			}
			for(Case c: new_1){
				sb_index.append("<li><a href=\"axxf/getOneCase.do?id="+c.getId()+"\">"+c.getTitle()+"</a></li>\n");
			}
			sb_index.append("</ul></div></div>\n");
			sb_index.append("<div class=\"col-lg-3\">\n");
			sb_index.append("<div class=\"widget\">\n");
			sb_index.append("<h5 class=\"widgetheading\">服务城市</h5>\n");
			sb_index.append("<ul class=\"link-list\">\n");
			if(sps.size() > 0){
				for(Map.Entry<String, List<Case>> entry : sps.entrySet()){
					sb_index.append("<li>"+entry.getKey()+"</li>\n");
				}
			}
			sb_index.append("</ul></div></div></div></div>\n");
			sb_index.append("<div class=\"container\">\n");
			sb_index.append("<p style=\"text-align: center;\">\n");
			sb_index.append(webinfo.getFooter()+"<a target=\"_blank\" href=\""+webinfo.getDomain()+"\">"+webinfo.getTitle()+"</a>\n");
			sb_index.append("</p></div></footer></div>\n");
			sb_index.append("<a href=\"#\" class=\"scrollup\"><i class=\"fa fa-angle-up active\"></i></a>\n");
			sb_index.append("</body>\n");
			sb_index.append("</html>\n");
			String file_content = sb_index.toString();
			OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file), "utf-8");
			writer.write(file_content);
			writer.flush();
			writer.close();
			logger.info("创建静态网页成功");
		} catch (IOException e) {
			logger.info("创建静态网页异常："+e);
		}
	}
	@RequestMapping("/getExampleByServiceId")
	public String getExampleByServiceId(int serviceId,HttpServletRequest request){
		logger.info("根据服务内容获取修复实例");
		Case t = new Case();
		t.setBelong(9);
		t.setParentId(serviceId);
		try {
			Case service = this.caseService.selectOne(serviceId);
			List<Case> selected = this.caseService.select(t, null);
			request.setAttribute("examples", selected);
			request.setAttribute("service", service);
			if(null == request.getSession().getAttribute("webinfo")){
				WebSite webinfo = this.adminService.getWebsitInfo();
				request.getSession().setAttribute("webinfo",webinfo );
			}
		} catch (Exception e) {
			logger.error("根据服务内容获取修复实例异常："+e);
			return "error.jsp";
		}
		return "/allExample.jsp";
	}
	@RequestMapping("/addBook")
	public void addBook(Case c,HttpServletRequest request,HttpServletResponse response){
		logger.info("添加留言信息……");
		try {
			c.setBelong(5);
			int save = this.caseService.save(new Case[]{c});
			response.setCharacterEncoding("utf-8");
			if(save > 0){
				response.getWriter().println("success");
			}
		} catch (Exception e) {
			logger.debug("添加留言信息异常，请联系开发人员"+e);
		}
	}
	@RequestMapping("/addBBS")
	public void addBSS(BBS bbs,HttpServletRequest request,HttpServletResponse response){
		logger.info("添加评论信息……");
		try {
			int userId =0;
			String struserId = request.getParameter("userId");
			if(StringUtil.isNotBlank(struserId)){
				userId = Integer.valueOf(struserId);
			}
			if(userId != 0){
				User u = new User();
				u.setId(userId);
				bbs.setUser(u);
			}
			int save = this.caseService.saveBBS(bbs);
			response.setCharacterEncoding("utf-8");
			if(save > 0){
				response.getWriter().println("success");
				logger.info("成功添加评论信息……");
			}
		} catch (Exception e) {
			logger.debug("添加评论异常，请联系开发人员"+e);
		}
	}
	
}
